package net.suncaper.demo.service;

import net.suncaper.demo.domain.Administrator;
import net.suncaper.demo.domain.Student;
import net.suncaper.demo.domain.Teacher;
import net.suncaper.demo.mapper.AdministratorMapper;
import net.suncaper.demo.mapper.StudentMapper;
import net.suncaper.demo.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private AdministratorMapper administratorMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private TeacherMapper teacherMapper;


    @Override
    public boolean ADverify(String id,String password) {
        Administrator administrator1 = findADById(id);
        if (administrator1==null){
            return false;
        }
        String password2 = administrator1.getPassword();
        if (password.equals(password2)) {
            return true;
        } else {
            return false;
        }
    }
    @Override
    public boolean TEverify(String id ,String password) {
        Teacher teacher1 = findTEById(id);
        if (teacher1==null){
            return false;
        }
        String password2 = teacher1.getPassword();
        if (password.equals(password2)) {
            return true;
        } else {
            return false;
        }
    }
    @Override
    public boolean STverify(String id ,String password) {
        Student student1 = findSTById(id);
        if (student1==null){
            return false;
        }
        String password2 = student1.getPassword();
        if (password.equals(password2)) {
            return true;
        } else {
            return false;
        }
    }

    public Administrator findADById(String administratorId) {
        return administratorMapper.selectByPrimaryKey(administratorId);
    }
    public Teacher findTEById(String teacherId) {
        return teacherMapper.selectByPrimaryKey(teacherId);
    }
    public Student findSTById(String studentId) {
        return studentMapper.selectByPrimaryKey(studentId);
    }

}
